package com.ruoyi.accounting.service.impl;

import com.ruoyi.accounting.domain.AccAccountingRecord;
import com.ruoyi.accounting.domain.dto.AccAccountingRecordImport;
import com.ruoyi.accounting.enums.AccountingRecordTypeEnum;
import com.ruoyi.accounting.service.AccountingRecordStrategy;
import com.ruoyi.common.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * 转账流水策略
 */
@Component
@Slf4j
public class TransferAccountingRecordStrategy implements AccountingRecordStrategy {
    @Override
    public void validate(AccAccountingRecord request) {
        if (request.getSourceAccountId() == null) {
            throw new ServiceException("源账户不能为空");
        }

        if (request.getTargetAccountId() == null) {
            throw new ServiceException("目标账户不能为空");
        }

        if (request.getSourceAccountId().equals(request.getTargetAccountId())) {
            throw new ServiceException("源账户不能等于目标账户");
        }

        if (request.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
            throw new ServiceException("转账金额必须大于0");
        }
    }

    @Override
    public void process(AccAccountingRecord request) {

    }

    @Override
    public Integer getType() {
        return AccountingRecordTypeEnum.TRANSFER.getCode();
    }

    @Override
    public List<AccAccountingRecord> importFromExcel(List<AccAccountingRecordImport> importList, Long bookId) {
        return null;
    }
}
